package com.geneqiao.jdbc;

import java.util.Arrays;
import java.util.Set;

import com.geneqiao.jdbc.util.DataUtils;

public class Sql
{
	private String sqlString;
	private Object[] objects;
	private Set<String> fields;
	private String className;
	private static final String NULL = "null";

	public <T> Sql(Class<T> cla, String sql, Object... objs)
	{
		this.sqlString = sql;
		this.objects = objs;
		this.className = cla.getName();
		this.fields = DataUtils.getDeclaredFields(cla);
	}

	public Sql(String sql, Object... objs)
	{
		this.sqlString = sql;
		this.objects = objs;
	}

	public static Sql parse(String sql)
	{
		return new Sql(sql, NULL);
	}
	
	public static Sql parse(String sql, Object... objs)
	{
		return new Sql(sql, objs);
	}

	public static <T> Sql parse(Class<T> cla, String sql)
	{
		return new Sql(cla, sql, NULL);
	}

	public static <T> Sql parse(Class<T> cla, String sql, Object... objs)
	{
		return new Sql(cla, sql, objs);
	}

	public String getSqlString()
	{
		return sqlString;
	}

	public Object[] getParameters()
	{
		return objects;
	}

	public Set<String> getFields()
	{
		return fields;
	}

	public String getClassName()
	{
		return className;
	}

	@Override
	public String toString()
	{
		return "Sql [sqlString=" + sqlString + ", objects=" + Arrays.toString(objects) + ", fields=" + fields
				+ ", className=" + className + "]";
	}
}
